home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / networking / pgpuam / sources / tsetuppane.cp < prev    next >
Encoding:
Text File  |  2000-06-23  |  6.9 KB  |  242 lines

  1. //    TSetupPane.cp -  AppleShare IP Dialog Pane Object
  2. // 
  3. // Apple Macintosh Developer Technical Support
  4. // Written by:  Vinnie Moscaritolo
  5. //
  6. //  Copyright (work in progress)  Apple Computer, Inc All rights reserved.
  7. //
  8. // You may incorporate this sample code into your applications without
  9. // restriction, though the sample code has been provided "AS IS" and the
  10. // responsibility for its operation is 100% yours.  However, what you are
  11. // not permitted to do is to redistribute the source as "DSC Sample Code"
  12. // after having made changes. If you're going to re-distribute the source,
  13. // we require that you make it clear in the source that the code was
  14. // descended from Apple Sample Code, but that you've made changes.
  15. // 
  16.  
  17.  
  18.  
  19. #include <Appearance.h>
  20.  
  21. #include "TSetupPane.h"
  22. #include "PassphraseCache.h"
  23. #include "PGPUAMclientLoginDialog.h"
  24.  
  25. static enum{
  26.     kSetupPaneDITL    = 141,
  27. };
  28.  
  29. enum
  30. {
  31.     kCachePassPhase    = 1,
  32.     kCacheTimeLimit, 
  33.     kTxt1Min,
  34.     kTxt2Min,
  35.     kTxt3Min,
  36.     kTxtAlways, 
  37.     kBorder2,
  38.     kAuthServer,
  39.     kOption1,
  40.     kOption2
  41. };
  42.  
  43. #define kSetupStringsID 141 
  44.  
  45. static enum {
  46.     k1MinStrID      =1,
  47.     k30MinStrID      ,
  48.     k60MinStrID      ,
  49.     kAlwaysStrID
  50.     };
  51.  
  52.  
  53.  // ---------------------------------------------------------------------------
  54. TSetupPane::TSetupPane( DialogPtr dialog, SInt16 items, TPGPUAMPrefs* prefs )
  55.                     : TPane (dialog, items) 
  56. // ---------------------------------------------------------------------------
  57. //
  58. {    
  59.     ControlFontStyleRec    fontInfo;
  60.     Str255                 text;
  61.  
  62.     fPrefs = prefs;
  63.     
  64.     AppendDialogItemList(dialog, kSetupPaneDITL, overlayDITL );
  65.  
  66. // box
  67.     fontInfo.flags = kControlUseFontMask;
  68.     fontInfo.font  = kControlFontSmallBoldSystemFont;
  69.      GetDialogItemAsControl( dialog, items + kCachePassPhase,     &fCachePassPhrase );
  70.     SetControlValue(fCachePassPhrase, fPrefs->GetCachePassPhrase());
  71.     SetControlData( fCachePassPhrase, 0, kControlStaticTextStyleTag, sizeof fontInfo, (Ptr)&fontInfo);
  72.  
  73.      GetDialogItemAsControl( dialog, items + kAuthServer,     &fAuthServer );
  74.     SetControlValue(fAuthServer, fPrefs->GetAuthenticateServer());
  75.     SetControlData( fAuthServer, 0, kControlStaticTextStyleTag, sizeof fontInfo, (Ptr)&fontInfo);
  76.  
  77.      GetDialogItemAsControl( dialog, items + kOption1,     &fOption1 );
  78.     SetControlValue(fOption1, fPrefs->GetOption1());
  79.     SetControlData( fOption1, 0, kControlStaticTextStyleTag, sizeof fontInfo, (Ptr)&fontInfo);
  80.  
  81.      GetDialogItemAsControl( dialog, items + kOption2,     &fOption2 );
  82.     SetControlValue(fOption2, fPrefs->GetOption2());
  83.     SetControlData( fOption2, 0, kControlStaticTextStyleTag, sizeof fontInfo, (Ptr)&fontInfo);
  84.  
  85. // tick strings
  86.     fontInfo.flags = kControlUseFontMask | kControlUseJustMask;
  87.     fontInfo.font = kControlFontSmallSystemFont;
  88.     fontInfo.just = teJustRight;
  89.     GetIndString(text, kSetupStringsID,kAlwaysStrID);
  90.     GetDialogItemAsControl( dialog, items + kTxtAlways,     &fTickLast );
  91.     SetControlData( fTickLast, 0, kControlStaticTextTextTag, text[0], (Ptr)(text+1));
  92.     SetControlData( fTickLast, 0, kControlStaticTextStyleTag, sizeof fontInfo, (Ptr)&fontInfo);
  93.  
  94.     fontInfo.just = teJustCenter;
  95.     GetIndString(text, kSetupStringsID,k60MinStrID);
  96.     GetDialogItemAsControl( dialog, items + kTxt3Min,     &fTick3 );
  97.     SetControlData( fTick3, 0, kControlStaticTextTextTag, text[0], (Ptr)(text+1));
  98.     SetControlData( fTick3, 0, kControlStaticTextStyleTag, sizeof fontInfo, (Ptr)&fontInfo);
  99.  
  100.     GetIndString(text, kSetupStringsID,k30MinStrID);
  101.     GetDialogItemAsControl( dialog, items + kTxt2Min,     &fTick2 );
  102.     SetControlData( fTick2, 0, kControlStaticTextTextTag, text[0], (Ptr)(text+1));
  103.     SetControlData( fTick2, 0, kControlStaticTextStyleTag, sizeof fontInfo, (Ptr)&fontInfo);
  104.  
  105.     fontInfo.just = teJustLeft;
  106.     GetIndString(text, kSetupStringsID,k1MinStrID);
  107.     GetDialogItemAsControl( dialog, items + kTxt1Min,     &fTick1 );
  108.     SetControlData( fTick1, 0, kControlStaticTextTextTag, text[0], (Ptr)(text+1));
  109.     SetControlData( fTick1, 0, kControlStaticTextStyleTag, sizeof fontInfo, (Ptr)&fontInfo);
  110.  
  111.     
  112. // slider
  113.       GetDialogItemAsControl( dialog, items + kCacheTimeLimit,     &fCacheTimeLimit );
  114.     SetControlMinimum(fCacheTimeLimit, 1);
  115.     SetControlMaximum(fCacheTimeLimit, 90);
  116.  
  117.     SetControlValue(fCacheTimeLimit, fPrefs->GetCachePassPhraseTimeLimit());
  118.     if (fPrefs->GetCachePassPhrase())
  119.     {
  120.         ActivateControl(fCacheTimeLimit);
  121.         ActivateControl(fTick1);
  122.         ActivateControl(fTick2);
  123.         ActivateControl(fTick3);
  124.         ActivateControl(fTickLast);
  125.     }
  126.     else
  127.     {
  128.         DeactivateControl(fCacheTimeLimit);
  129.         DeactivateControl(fTick1);
  130.         DeactivateControl(fTick2);
  131.         DeactivateControl(fTick3);
  132.         DeactivateControl(fTickLast);
  133.     }
  134.  
  135.  
  136. // deactivate till we know what to do with them
  137.     DeactivateControl(fOption1);
  138.     DeactivateControl(fOption2);
  139.  
  140.     ShowControl(fCachePassPhrase);
  141.     
  142. }    
  143.  
  144.  
  145.  
  146. // ---------------------------------------------------------------------------
  147. TSetupPane::~TSetupPane()
  148. // ---------------------------------------------------------------------------
  149. //
  150. {     
  151.      
  152.      ShortenDITL( fDialog, CountDITL(fDialog) - fOrigItems);
  153. }
  154.  
  155.  
  156. // ---------------------------------------------------------------------------
  157. void TSetupPane::Refresh(void)
  158. // ---------------------------------------------------------------------------
  159. //
  160. {     
  161. }
  162.  
  163.  
  164. // ---------------------------------------------------------------------------
  165. void TSetupPane::Idle(void)
  166. // ---------------------------------------------------------------------------
  167. //
  168. {     
  169.  
  170. }
  171.  
  172.  
  173. // ---------------------------------------------------------------------------
  174. void TSetupPane::ItemHit(SInt16 item)
  175. // ---------------------------------------------------------------------------
  176. //
  177. {     
  178.     SInt16            localItem;
  179.     Boolean         enable;
  180.     
  181.     localItem = item - fOrigItems;
  182.     
  183.     switch ( localItem )
  184.     {
  185.         case kCachePassPhase:
  186.             enable = (GetControlValue(fCachePassPhrase) == 0) ;
  187.          
  188.                SetControlValue(fCachePassPhrase, enable);
  189.             fPrefs->SetCachePassPhrase(enable);
  190.             EnablePassphraseCaching(enable);
  191.             
  192.                 if (enable)
  193.             {
  194.                 ActivateControl(fCacheTimeLimit);
  195.                 ActivateControl(fTick1);
  196.                 ActivateControl(fTick2);
  197.                 ActivateControl(fTick3);
  198.                 ActivateControl(fTickLast);
  199.                 SetPassphraseCacheTimeLimit( GetControlValue(fCacheTimeLimit) );
  200.             }
  201.             else
  202.             {
  203.                 DeactivateControl(fCacheTimeLimit);
  204.                 DeactivateControl(fTick1);
  205.                 DeactivateControl(fTick2);
  206.                 DeactivateControl(fTick3);
  207.                 DeactivateControl(fTickLast);
  208.                 SetPassphraseCacheTimeLimit( 0 );
  209.  
  210.             }
  211.              break;
  212.             
  213.         case kCacheTimeLimit:
  214.             if( GetControlValue(fCacheTimeLimit) != fPrefs->GetCachePassPhraseTimeLimit() )
  215.             {
  216.                 fPrefs->SetCachePassPhraseTimeLimit(GetControlValue(fCacheTimeLimit));
  217.                 SetPassphraseCacheTimeLimit( GetControlValue(fCacheTimeLimit)   );
  218.             }
  219.             break;
  220.     
  221.         case kAuthServer:
  222.             enable = (GetControlValue(fAuthServer) == 0) ;
  223.                SetControlValue(fAuthServer, enable);
  224.             fPrefs->SetAuthenticateServer(enable);
  225.             break;
  226.             
  227.         case kOption1:
  228.             enable = (GetControlValue(fOption1) == 0) ;
  229.                SetControlValue(fOption1, enable);
  230.             fPrefs->SetOption1(enable);
  231.             break;
  232.             
  233.         case kOption2:        
  234.             enable = (GetControlValue(fOption1) == 0) ;
  235.                SetControlValue(fOption1, enable);
  236.             fPrefs->SetOption2(enable);
  237.             break;
  238.      }
  239.  
  240. }
  241.  
  242.